package com.myres.service;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.myres.dao.ProductDao;
import com.myres.model.Product;

public class ProductService {
	private ProductDao productDao;

	public ProductDao getProductDao() {
		return productDao;
	}

	public void setProductDao(ProductDao productDao) {
		this.productDao = productDao;
	}

	public Product get(int id) {
		return productDao.get(id);
	}

	public int save(Product product) {
		return productDao.save(product);
	}

	public int update(Product product) {
		return productDao.update(product);
	}

	public void delete(Product product) {
		productDao.delete(product);
	}

	public void delete(int id) {
		productDao.delete(id);
	}

	@SuppressWarnings("unchecked")
	public List<Product> findByName(String name) {
		return productDao.findByName(name);
	}

	@SuppressWarnings("unchecked")
	public List<Product> findAll() {
		return productDao.findAll();
	}

	public List<Product> findAllOnIndex() {
		return productDao.findAllOnIndex();
	}

	public List<Product> findAllOnPromotion() {
		return productDao.findAllOnPromotion();
	}

	public List<Product> findAllOnRecommend() {
		return productDao.findAllOnRecommend();
	}

	/**
	 * 
	 * @param startWith
	 *            keep null if you don't want to use in range function.
	 * @param size
	 *            same as this one.
	 * @return
	 */
	public List<Product> findAllOrderByPriceInRange(Integer startWith,
			Integer size) {
		return productDao.findAllOrderByPriceInRange(startWith, size);
	}

	/**
	 * 
	 * @param startWith
	 *            keep null if you don't want to use in range function.
	 * @param size
	 *            same as this one.
	 * @return
	 */
	public List<Product> findAllOrderByScoreInRange(Integer startWith,
			Integer size) {
		return productDao.findAllOrderByScoreInRange(startWith, size);
	}

	/**
	 * 
	 * @param name
	 * @param startWith
	 *            keep null if you don't want to use in range function.
	 * @param size
	 *            same as this one.
	 * @return
	 */
	public List<Product> findbyNameOrderByPriceInRange(String name,
			Integer startWith, Integer size) {
		return productDao.findbyNameOrderByPriceInRange(name, startWith, size);
	}

	/**
	 * 
	 * @param name
	 * @param startWith
	 *            keep null if you don't want to use in range function.
	 * @param size
	 *            same as this one.
	 * @return
	 */
	public List<Product> findbyNameOrderByScoreInRange(String name,
			Integer startWith, Integer size) {
		return productDao.findbyNameOrderByScoreInRange(name, startWith, size);
	}
}
